<?php
$loadid="";
if(isset($_GET['loadid'])) {
	//echo "loadid:";
	//echo $_GET['loadid'];
	$loadid=$_GET['loadid'];
$names = preg_split("/_/", $loadid);
if(strcmp($names[0], $names[1]) >=0 ) {
        $postdst = "$names[0]_$names[1]";
}
else
        $postdst = "$names[1]_$names[0]";

	//echo "<meta content='5; url=history.php?loadid=$loadid' http-equiv='refresh'>";
	#echo "<textarea id=textarea_id rows=\"20\" cols=\"100\">";
	#echo file_get_contents($postdst);
	#echo "</textarea>";
	echo "<div id=textarea_id style=\"width:700px;height:500px;overflow:auto;background-color:black;border: 6px outset red;color: white;padding: 5px;margin:2px;border-radius: 4px;\">";
	if(file_exists("chat/$postdst"))
			file_get_contents("chat/$postdst");
	echo "</div>";
	echo "<script lang=javascript>";
	echo "var textarea = document.getElementById('textarea_id');";
	echo "textarea.scrollTop = textarea.scrollHeight;";
	echo "</script>";
}
else
	echo "noloadid";
?>
<script lang=javascript>
setTimeout("updateChatAJAx()", 2000);
    function updateChatAJAx(){
        var ajaxRequest;  // The variable that makes Ajax possible!
	setTimeout("updateChatAJAx()", 2000);

        ajaxRequest = new XMLHttpRequest();
        // Create a function that will receive data sent from the server
        ajaxRequest.onreadystatechange = function(){
                if(ajaxRequest.readyState == 4){
                        //The response
                        document.getElementById('textarea_id').innerHTML = ajaxRequest.responseText;
	var textarea = document.getElementById('textarea_id');;
	textarea.scrollTop = textarea.scrollHeight;;
                }
        }
<?php
        echo "ajaxRequest.open(\"GET\", \"history_data.php?loadid=$loadid\", true);";
?>
        ajaxRequest.send(null);
}

</script>

